package cn.edu.sdjzu.xg.eagle.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author tg.si@188.com
 * @todo
 * @since 2024/4/16 10:31
 */
@WebFilter(filterName = "encoding1", urlPatterns = {"/*"})
public class EncodingFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
//        Filter.super.init(filterConfig);
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
//        System.out.println("EncodingFilter is invoked");
        //设置响应字符编码为UTF-8
        HttpServletResponse httpServletResponse = (HttpServletResponse)response;
        httpServletResponse.setContentType("application/json;charset=UTF-8");
        chain.doFilter(request, response);
//        System.out.println("EncodingFilter ends");
    }

    @Override
    public void destroy() {
//        Filter.super.destroy();
    }
}
